<template>
    <div style="background-color: #fafafa;height: 100%">
            <yd-infinitescroll  :callback="loadList" ref="infinitescrollDemo" >
                <yd-list theme="4" slot="list" style="background-color: #fafafa;padding-left: 15px;padding-right: 15px">
                    <div v-for="(item,index) in dataAr">
                        <p class="time">{{item.created}}</p>
                        <div class="context-background">
                            <p class="name">{{item.title}}</p>
                            <p class="context">{{item.brief}}</p>
                        </div>
                    </div>
                </yd-list>
            </yd-infinitescroll>

        <!--<div v-else>-->
            <!--<img src="../../assets/nolist.png" class="nolist-image" alt="">-->
            <!--<p  class="nolist-tite">暂无内容</p>-->
        <!--</div>-->
    </div>
</template>

<script>
    import {showSystemNotify} from "../../pcof/post";
    import {userInfoData} from '../../globalVariables'

    export default {
        name: "systemMessage",
        data()
        {
            return{
                pageNumber: 1,
                pageSize: 20,
                serviceTotalPage: 1,
                dataAr:[],
            };
        },
       async created()
        {

            var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
            this.$dialog.loading.open('加载中...');
            this.pageNumber=1;
            this.pageSize=20;
            var response = await showSystemNotify(mobile,this.pageNumber,this.pageSize);
            if (response.data.code === 200) {
                this.$dialog.loading.close();
                this.dataAr = response.data.data.list;
                this.serviceTotalPage = response.data.data.totalPage;
                if (this.serviceTotalPage > 1) {
                    this.page++;
                } else {
                    /* 所有数据加载完毕 */
                    this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
                }
            }else
            {
                this.$dialog.loading.close();
                console.log(response.data.msg);
                this.$dialog.toast({
                    mes: response.data.msg,
                    timeout: 1500
                });
            }

        },
        methods:
        {
            async loadList() {
            // mobile, bankUuid,latitude,longitude,keyword,pageNumber,pageSize

            var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
            var response = await showSystemNotify(mobile,this.pageNumber, this.pageSize);
            if (response.data.code === 200) {
                const _list = response.data.data.list;
                this.dataAr = [...this.dataAr, ..._list];
                if (_list.length < this.pageSize || this.pageNumber === this.serviceTotalPage) {
                    /* 所有数据加载完毕 */
                    this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
                    return;
                }

                /* 单次请求数据完毕 */
                this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.finishLoad');
                this.pageNumber++;

            } else {

            }
        },
        }
    }
</script>

<style lang="scss">
    @import "./messsge.scss";

</style>